package com.zygh.policeasset.task;

import com.zygh.policeasset.config.CronTaskRegistrar;
import com.zygh.policeasset.config.SchedulingRunnable;
import com.zygh.policeasset.mapper.NoticeAfficheMapper;
import com.zygh.policeasset.mapper.NoticeAfficheUserMapper;
import com.zygh.policeasset.mapper.TaskMapper;
import com.zygh.policeasset.mapper.UserMapper;
import com.zygh.policeasset.pojo.NoticeAffiche;
import com.zygh.policeasset.pojo.NoticeAfficheUser;
import com.zygh.policeasset.pojo.Task;
import com.zygh.policeasset.pojo.User;
import java.util.ArrayList;
import java.util.List;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

@Component("NoticeAfficheTask")
/* loaded from: police-asset-2.0-0.0.1-SNAPSHOT.jar:BOOT-INF/classes/com/zygh/policeasset/task/NoticeAfficheTask.class */
public class NoticeAfficheTask implements CommandLineRunner {
    @Autowired
    TaskMapper taskMapper;
    @Autowired
    CronTaskRegistrar cronTaskRegistrar;
    @Autowired
    NoticeAfficheMapper noticeAfficheMapper;
    @Autowired
    NoticeAfficheUserMapper noticeAfficheUserMapper;
    @Autowired
    UserMapper userMapper;

    @Override // org.springframework.boot.CommandLineRunner
    public void run(String... args) {
        List<Task> tasks = this.taskMapper.queryTask();
        if (tasks.size() > 0) {
            for (int i = 0; i < tasks.size(); i++) {
                this.cronTaskRegistrar.addCronTask(new SchedulingRunnable(tasks.get(i).getBeanName(), tasks.get(i).getMethoDname(), JSONObject.fromObject(tasks.get(i)).toString()), tasks.get(i).getTaskTime());
            }
        }
    }

    public void noticeAffiche(String params) {
        System.out.println("定时任务执行了" + params);
        Task task = (Task) JSONObject.toBean(JSONObject.fromObject(params), Task.class);
        NoticeAffiche noticeAffiche = this.noticeAfficheMapper.selectById(task.getNoticeAfficheId().intValue());
        NoticeAffiche noticeAffiche1 = new NoticeAffiche();
        noticeAffiche1.setId(task.getNoticeAfficheId());
        if (noticeAffiche.getStatus().intValue() == 2) {
            List<NoticeAfficheUser> noticeAfficheUserList = new ArrayList<>();
            if (1 == noticeAffiche.getType().intValue()) {
                List<User> findAllUser = this.userMapper.findAllUser(null, null);
                for (int i = 0; i < findAllUser.size(); i++) {
                    NoticeAfficheUser noticeAfficheUser = new NoticeAfficheUser();
                    noticeAfficheUser.setNoticeAfficheId(task.getNoticeAfficheId());
                    noticeAfficheUser.setStatus(0);
                    noticeAfficheUser.setUserId(Integer.valueOf(findAllUser.get(i).getId()));
                    noticeAfficheUserList.add(noticeAfficheUser);
                }
            } else {
                for (String str : noticeAffiche.getUsers().split(",")) {
                    NoticeAfficheUser noticeAfficheUser2 = new NoticeAfficheUser();
                    noticeAfficheUser2.setNoticeAfficheId(task.getNoticeAfficheId());
                    noticeAfficheUser2.setStatus(0);
                    noticeAfficheUser2.setUserId(Integer.valueOf(Integer.parseInt(str)));
                    noticeAfficheUserList.add(noticeAfficheUser2);
                }
            }
            System.out.println(task);
            this.noticeAfficheUserMapper.insertBatch(noticeAfficheUserList);
            noticeAffiche1.setSend(1);
            this.noticeAfficheMapper.update(noticeAffiche1);
            return;
        }
        noticeAffiche1.setSend(2);
        this.noticeAfficheMapper.update(noticeAffiche1);
    }
}